﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace LastStand.gameContent.enemies
{
	public class meleeAttacker : Enemy
	{
		private int direction = 1;
		private bool atDest;

		public meleeAttacker(Vector2 orig, Texture2D tex)
		{
			//initialize our sprite variables
			this.OriginPos = orig;
			this.Position = orig;
			this.Velocity = new Vector2(.025f, 1f);
			this.Texture = tex;
			this.Scale = .5f;
			//this.angle = 180f;

			//and then the enemy variables
			this.health = 100;
			this.attackDistance = 10f;
			this.attackTimer = 1650f;
			//this.attackDamage = 10f;
			this.canAttack = false;

			this.navDest = orig;
			this.atDest = false;
		}

		public override void Update(GameTimerEventArgs elapsedTime)
		{
			//if we're near our navDest
			if ((int)this.GetPosition.X <= (int)this.navDest.X && atDest == false)
			{
				//then we are at our destination and ready to find
				//another one.
				this.atDest = true;

				//randomizer
				Random rand = new Random();

				//new navDest xPos and yPos
				float navX;
				float navY;

				//amount of milliseconds it will take
				//for the sprite to reach navDest
				float deltaXtime;

				//new Y-velocity to be found
				float yVelocity;

				//randomize new navY destination, multiply
				//by direction for zigzag direction change
				navY = rand.Next(25, 75) * direction;

				//get new navX destination
				navX = rand.Next(25, 80);

				this.navDest.X = this.GetPosition.X - navX;
				this.navDest.Y = this.GetPosition.Y + navY;

				//find milliseconds to reach navDest Xpos based on velocity
				//pos = velocity * time
				//time = pos / velocity
				deltaXtime = navX / this.GetVelocity.X;

				//use deltaXtime to determine the y-velocity for movement
				yVelocity = navY / deltaXtime;

				//set new velocity
				this.VelocityY = yVelocity;

				//flip direction for next time
				this.direction *= -1;

				//we are not at the destination
				this.atDest = false;
              
			}

			else
			{
				this.position.X -= this.GetVelocity.X * elapsedTime.ElapsedTime.Milliseconds;
				this.position.Y += this.GetVelocity.Y * elapsedTime.ElapsedTime.Milliseconds;
			}
		}

		public override void Draw(SpriteBatch sb)
		{
			sb.Draw(this.Texture,
				this.GetPosition,
				null,
				Microsoft.Xna.Framework.Color.White,
				angle,
				Vector2.Zero,
				this.GetScale,
				SpriteEffects.None,
				0);
		}

		protected override void move(GameTimerEventArgs elapsedTime)
		{
			//if we are at or near enough our destination, we will find
			//a new one to go to.

		}

		protected override void attack()
		{
			base.attack();
		}

		protected override void takeDamage()
		{
			base.takeDamage();
		}
	}
}
